{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4b51d354",
   "metadata": {},
   "source": [
    "## cd/回到根路径\n",
    "## 上周回顾\n",
    "> *1.list 的一般方法/函数的使用及案例\n",
    ">> 1.append()增加，增加liat元素到list末尾\n",
    ">> 2.pop(index)/remove(values)对比两者优势\n",
    ">> 3.count()查看某个元素出现的次数\n",
    ">> 4.index()查看某个元素第一次出现的位置\n",
    ">> 5.extend()两个list合并在一起，也可『』+『』实现\n",
    " \n",
    "> *2.list的高级用法\n",
    ">> 1.copy（）list（可变的数据类型）复制 不等于赋值，可用『：』\n",
    ">>2.enumerate（）枚举，可同时遍历并获取index和values\n",
    "\n",
    "## 本周内容\n",
    "### list练习，vowels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "906f6394",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels=['a','e','i','o','u']\n",
    "word=\"Milliways\"\n",
    "#检查word中出现的元音，并打印出来怎么做？\n",
    " #第一个元素letter 请不要和已有变量重名\n",
    "#第一个元素一般不定义名字，常用item（元素）来命名，简写i\n",
    "\n",
    "#第二个元素（重要），意味着将遍历的内容\n",
    "#遍历内容一般是序列数据str list\n",
    "for letter in word:\n",
    "#     print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f43b4de",
   "metadata": {},
   "source": [
    "## vowels2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5bb7113f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['i', 'a']\n"
     ]
    }
   ],
   "source": [
    "#使用append（）新建列表\n",
    "found=[]\n",
    "for letter in word:\n",
    "#     print(letter)\n",
    "    if letter in vowels:#letter在元音字母表中\n",
    "        if letter not in found:#letter不在found表中\n",
    "            found.append(letter)\n",
    "print(found)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47b4e3f6",
   "metadata": {},
   "source": [
    "### list实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c8b26c8b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的余额:44444\n",
      "['A价格=30', 'B价格=100', 'C价格=60']\n",
      "请输入您要购买的商品名字:A\n",
      "请输入您购买商品的价格:A\n",
      "['A', 'A', 'A']\n"
     ]
    }
   ],
   "source": [
    "#购物车程序项目\n",
    "#第一次自己写，有许多错误和不会\n",
    "\n",
    "goods_list1=[\"A价格=30\",\"B价格=100\",\"C价格=60\"]\n",
    "goods_list=[\"A\",\"B\",\"C\"]\n",
    "user_shopping_list=[]\n",
    "user_money=input(\"请输入您的余额:\")\n",
    "print(goods_list1)\n",
    "uesr_goods=input(\"请输入您要购买的商品名字:\")\n",
    "uer_price=input(\"请输入您购买商品的价格:\")\n",
    "for i in goods_list:\n",
    "   \n",
    "    if i not in usre_shopping_list:\n",
    "            user_shopping_list.append(uesr_goods)\n",
    "            \n",
    "print(user_shopping_list)\n",
    "\n",
    "#     if uers_money > uer_price:\n",
    "#         print(\"购买成功\")\n",
    "# print(\"您的余额=\"uers_money-uer_price)\n",
    "#     else:\n",
    "#         print(\"余额不足\")\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d611016e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#商品信息的数据存放（商品编号，商品名称，商品价格）\n",
    "goods_list=[[\"a\",1],[\"b\",2],[\"c\",3]]#我们认为每个商品都是一个多个值的值，可选用list\n",
    "#用户购物信息的数据存放\n",
    "user_shopping_list=[]#增加进来可考虑用appen（）方法\n",
    "用户输入余额信息\n",
    "Alipay=input(\"请输入支付宝余额：\")\n",
    "#打印商品信息，list长度？len()\n",
    "print('------goods list------')\n",
    "for i in range(len(goods_liat))：\n",
    "    print(\"商品编号：%s,商品名称：%s,商品价格%s元\"%(i,goods_list[i][0],goods_list[i])\n",
    "#用户输入商品编号，实现商品查询\n",
    "choice=int(input(\"输入商品的编号：\"))#input输入内容默认是str\n",
    "#判断编号是否存在\n",
    "if choice < len(goods_list):\n",
    "    #检查用户余额 > 商品价格\n",
    "    if Alipay > goods_list[choice][1]  \n",
    "    Alipay=Alipay - goods_list[choice][1]\n",
    "     Alipay.append(goods_list[choice])\n",
    "    \n",
    "else:\n",
    "    print(\"请输入正确的商品编号，您输入的商品不存在\")\n",
    "#打印用户数据余额和用户商品列表信息\n",
    "print(\"用户数据余额：%s，购物车：%s\"%( Alipay,user_shopping_list))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d51909a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
